import $ from 'jquery'

// 在手机端访问时，必须将地址改成本机内网IP
var apiUrl = 'http://10.188.0.26:8091/';

export default {
  // 获取电影列表
  getFilmList: function (type, offset, limit, success) {
    $.ajax({
      url: apiUrl + 'https://m.maoyan.com/movie/list.json',
      type: 'get',
      dataType: 'json',
      data: {
        type: type,
        offset: offset,
        limit: limit
      },
      success: function (data) {
        success(data)
      },
      error: function (err) {
        console.log(err);
      }
    })
  },
  //获取电影信息
  getFilmInfo: function (id, success) {
    console.log('https://m.maoyan.com/movie/' + id + '.json');
    $.ajax({
      url: apiUrl + 'https://m.maoyan.com/movie/' + id + '.json',
      type: 'get',
      dataType: 'json',
      data: {
        movieid: id
      },
      success: function (data) {
        success(data);
      },
      error: function (err) {
        console.log(err);
      }
    })
  },
  // 获取更多评论
  getFilmComments: function (id, offset, limit, success) {
    $.ajax({
      url: apiUrl + 'http://m.maoyan.com/comments.json',
      type: 'get',
      dataType: 'json',
      data: {
        movieid: id,
        offset: offset,
        limit: limit
      },
      success: function (data) {
        success(data);
      },
      error: function (err) {
        console.log(err);
      }
    })
  },
  //获取影院列表
  getCinemaList: function (success) {
    $.ajax({
      url: apiUrl + 'https://m.maoyan.com/cinemas.json',
      type: 'get',
      dataType: 'json',
      success: function (data) {
        success(data);
      },
      error: function (err) {
        console.log(err);
      }
    })
  },
  // 获取电影院信息
  getCinemaInfo: function (cinemaId, movieId, success) {
    $.ajax({
      url: apiUrl + 'http://m.maoyan.com/showtime/wrap.json',
      type: 'get',
      dataType: 'json',
      data: {
        cinemaid: cinemaId,
        movieid: movieId || ''
      },
      success: function (data) {
        success(data);
      },
      error: function (err) {
        console.log(err);
      }
    })
  }
}
